package com.yy.utils;

import com.yy.mapper.LockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class DistributeLockFactory {
    @Autowired
    StringRedisTemplate redisTemplate;
    String uuid;

    @Autowired
    ZkClient zkClient;

    public DistributeLockFactory() {
        this.uuid = UUID.randomUUID().toString();
    }


    public RedisDistributeLock getRedisLock(String lockName) {
        return new RedisDistributeLock(redisTemplate, lockName, uuid);
    }

    public ZkDistributeLock getZkLock(String lockName) {
        return new ZkDistributeLock(zkClient.getZooKeeper(), lockName);
    }

    public MysqlDistributeLock getMysqlLock(LockMapper lockMapper, String lockName) {
        return new MysqlDistributeLock(lockMapper, lockName);
    }
}
